/*
 * Copyright (c) 2017, MegaEase
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.megaease.easeagent.zipkin.impl;

import com.megaease.easeagent.plugin.api.trace.Request;
import com.megaease.easeagent.plugin.api.trace.Span;

import java.util.HashMap;
import java.util.Map;

public class AsyncRequest implements Request {
    private final Request request;
    private final Map<String, String> header;

    public AsyncRequest(Request request) {
        this.request = request;
        this.header = new HashMap<>();
    }

    @Override
    public Span.Kind kind() {
        return request.kind();
    }

    @Override
    public String name() {
        return request.name();
    }

    @Override
    public String header(String name) {
        String value = request.header(name);
        return value == null ? header.get(name) : value;
    }

    @Override
    public boolean cacheScope() {
        return request.cacheScope();
    }

    @Override
    public void setHeader(String name, String value) {
        request.setHeader(name, value);
        header.put(name, value);
    }

    public Map<String, String> getHeaders() {
        return header;
    }
}
